<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge，chrome=1">
    <meta name="renderer" content="webkit">
    <script src="../../../node_modules/jquery/dist/jquery.min.js"></script>
    <link rel="stylesheet" href="../../../node_modules/bootstrap/dist/css/bootstrap.min.css">
    <script src="../../../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="../../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="../../../node_modules/vue/dist/vue.min.js"></script>
    <link rel="stylesheet" href="../../../node_modules/element-ui/lib/theme-chalk/index.css">
    <script src="../../../node_modules/element-ui/lib/index.js"></script>
    <script src="../../../node_modules/echarts/dist/echarts.js"></script>


    <!-- 自定义 -->
    <script src="../../../node_modules/mockjs/dist/mock.js"></script>
    <script src="../static/js/mock_config.js"></script>
    <script src="../static/js/index.js"></script>
    <link rel="stylesheet" href="../../index.css">
    <!-- <script src="../static/js/echarts.min.js"></script> -->

    <!-- PC -->
    <link rel="stylesheet" href="../static/css/ZiPurchase.css" media="only screen and (max-height:1600px) ">
    <!-- 手机App -->
    <link rel="stylesheet" href="../static/css/ZiPurchaseApp.css" media="only screen and (min-height:1600px) ">

</head>

<body>
    <!--主体-->
    <div class="main clearfix" id="app">
        <div class="header" style="padding-top: 25px; ">
            <header>
                <div class="navbar">
                    <div class="card A" style="min-width:16rem;background-color:#0b87fa;color: white;">
                        <ul class="header-text">
                            <li>
                                <h8 style="line-height: 78px;">采购看板</h8>
                            </li>
                        </ul>

                    </div>
                    <div class="card B">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <h4>供应商</h4>
                            </li>
                            <li class="list-group-item1">
                                <h3 id="Supplier">0
                                </h3>
                            </li>
                        </ul>
                    </div>
                    <div class="card C">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <h4>本年材料采购订单</h4>
                            </li>
                            <li class="list-group-item1">
                                <h3 id="YearGoods">0</h3>
                            </li>
                        </ul>
                    </div>
                    <div class="card D" >
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <h4>本年总采购订单</h4>
                            </li>
                            <li class="list-group-item1">
                                <h3 id="YearPurchase">0</h3>
                            </li>
                        </ul>
                    </div>
                </div>
            </header>
        </div>


        <div class="body_div">
            <div class="main-left">
                <div class="border-container3">
                    <div class="name-title">
                        采购额同比
                    </div>
                    <div>
                        <div id="linian"></div>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
                <div class="border-container3">
                    <div class="name-title">
                        本年供应商对账额排名（前10）
                    </div>
                    <div>
                        <el-table :data="defaultDt1" :default-sort="{prop: 'date', order: 'descending'}" stripe="true" ref="defaultDt1" :height=el_table_height4 :cell-style="{padding:3+'px'}">
                            <el-table-column type="index" width="50" label="序号">
                            </el-table-column>
                            <el-table-column prop="SupplierCode" align="center" label="供应商">
                            </el-table-column>
                            <el-table-column align="center" label="占比排名">
                                <template slot-scope="scope">
                                    <div v-html="Kecutout(scope)">
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
            </div>
            <div class="center">
                <div class="border-container3">
                    <div class="name-title">
                        年度采购订单类型占比分析
                    </div>
                    <div>
                        <div id="YearPurOrder" style="width:100%;height: 430px;"></div>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>

                <div class="border-container3">
                    <div class="name-title">
                        材料采购VS贸易采购分析
                    </div>
                    <div>
                        <div id="Purchase" style="height: 400px; width: 100%;"></div>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
            </div>
            <div class="main-right">
                <div class="border-container3">
                    <div class="name-title">
                        常购材料排行(前30)
                    </div>
                    <div>
                        <el-table :data="defaultDt2" :default-sort="{prop: 'date', order: 'descending'}" stripe="true" ref="defaultDt2" :height=el_table_height4 :cell-style="{padding:3+'px'}">
                            <el-table-column type="index"  width="50" label="序号">
                            </el-table-column>
                            <el-table-column prop="GoodsName" min-width="180" align="center" label="材料名称">
                            </el-table-column>
                            <el-table-column prop="Quantity" align="center" label="总采购数量">
                            </el-table-column>
                            <el-table-column prop="Number" align="center" label="次数">
                            </el-table-column>
                            <el-table-column prop="TaxAmtOrd" align="center" label="金额">
                            </el-table-column>
                        </el-table>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
                <div class="border-container3">
                    <div class="name-title">
                        主要材料价格异动分析
                    </div>
                    <div>
                        <el-table :data="defaultDt3" :default-sort="{prop: 'date', order: 'descending'}" stripe="true" ref="defaultDt3" :height=el_table_height4 :cell-style="{padding:3+'px'}">
                            <el-table-column prop="goodsname"  min-width="180" align="center" label="材料名称">
                            </el-table-column>
                            <el-table-column prop="Ten" align="center" label="本次单价">
                            </el-table-column>
                            <el-table-column prop="Nine" align="center" label="上次单价">
                            </el-table-column>
                            <el-table-column prop="Increase" align="center" label="涨幅">
                            </el-table-column>
                            <el-table-column prop="Increaseratio" align="center" label="涨幅比率">
                            </el-table-column>
                        </el-table>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
            </div>
        </div>
    </div>

</body>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                el_table_height4: 422,
                linian: null,
                YearPurOrder: null,
                Purchase: null,
                defaultDt1: [],
                defaultDt2: [],
                defaultDt3:[],
                option1: {
                    xAxis: {
                        type: 'category',
                        data: ['2019', '2020', '2021']
                    },
                    yAxis: {
                        type: 'Goods'
                    },
                    series: [{
                        data: [120, 200, 150, 80, 70, 110, 130],
                        type: 'bar',
                        itemStyle: { //上方显示数值
                            normal: {
                                label: {
                                    show: true, //开启显示
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: 'white'
                                    }
                                }
                            }
                        }
                    }]
                },
                option2: {
                    title: {
                        top: '2%',
                        textStyle: { //图例文字的样式
                            color: '#12f0e9 ',
                            fontSize: 20
                        },
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        top: '10%',
                        orient: 'vertical',
                        left: 'left',
                        textStyle: { //图例文字的样式
                            color: 'white ',
                            fontSize: 14

                        },
                    },
                    series: [{
                        radius: ['40%', '70%'],
                        name: '年度采购订单类型占比分析',
                        type: 'pie',
                        avoidLabelOverlap: false,
                        itemStyle: {
                            borderRadius: 10,
                            borderColor: '#fff',
                            borderWidth: 1
                        },
                        label: {
                            show: false,
                            position: 'center'
                        },
                        emphasis: {
                            label: {
                                show: true,
                                fontSize: '20',
                                fontWeight: 'bold',
                                color: '#12f0e9'
                            }
                        },
                        labelLine: {
                            show: false
                        },
                        data: [{
                            Goods: 1048,
                            name: '搜索引擎'
                        }, {
                            Goods: 735,
                            name: '直接访问'
                        }],
                    }]
                },
                option3: {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            crossStyle: {
                                color: '#999'
                            }
                        }
                    },
                    legend: {
                        textStyle: {
                            color: '#00FFFFF'
                        }
                    },
                    xAxis: [{
                        type: 'category',
                        color: 'white',
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                        axisPointer: {
                            type: 'shadow'
                        },
                        axisLabel: {
                            textStyle: {
                                color: "#FFF"
                            }
                        },
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLabel: {
                            formatter: '{value} (万元)',
                            textStyle: { //改变xy轴上文字的颜色
                                color: "#FFF"
                            }
                        }
                    }],
                    series: [{
                        name: '材料采购',
                        type: 'bar',
                        data: [],
                        itemStyle: { //上方显示数值
                            normal: {
                                label: {
                                    show: true, //开启显示
                                    formatter: function(params) {
                                        if (params.value > 0) {
                                            return params.value;
                                        } else {
                                            return '';
                                        }
                                    },
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: 'white'
                                    }
                                }
                            }
                        }
                    }, {
                        name: '贸易采购',
                        type: 'bar',
                        data: [],
                        itemStyle: { //上方显示数值
                            normal: {
                                label: {
                                    show: true, //开启显示
                                    formatter: function(params) {
                                        if (params.value > 0) {
                                            return params.value;
                                        } else {
                                            return '';
                                        }
                                    },
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: 'white'
                                    }
                                }
                            }
                        }
                    }]
                },
            }
        },
        methods: {
            GetTabelDate(that) {
                //供应商
                GetCodeData("VB21102611502857", "Get", "Goods").then(function(res) {
                        $('#Supplier').text("" + res.rows[0].Total + "家")
                    }),
                    //本年材料采购订单
                    GetCodeData("VB21102611505868", "Get", "Goods").then(function(res) {
                        $('#YearGoods').text("" + res.rows[0].Total + "万元")
                    }),
                    //本年总采购订单
                    GetCodeData("VB21102611512642", "Get", "Goods").then(function(res) {
                        $('#YearPurchase').text("" + res.rows[0].Total + "万元")
                    }),
                    //历年支出
                    GetCodeData("VB21110811311871", "Get", "Goods").then(function(res) {
                        //echarts柱状图
                        var chartDom = document.getElementById('linian');
                        var myChart = echarts.init(chartDom);
                        var xAxisData = []; //X轴数据
                        var seriesData = []; //系列数据

                        if (res.rows != null && res.rows.length > 0) {
                            for (var i = 0; i < res.rows.length; i++) {
                                xAxisData.push(res.rows[i]["DeliveryYear"]);
                                seriesData.push(res.rows[i]["TaxAmtDelivery"]);
                            }
                        }
                        var option = {
                            xAxis: {
                                type: 'category',
                                data: xAxisData
                            },
                            yAxis: {
                                type: 'value'
                            },
                            series: [{
                                data: seriesData,
                                type: 'bar',
                                label: {
                                    show: true,
                                    position: 'top',
                                    textStyle: { //数值样式
                                            color: 'white'
                                    },
                                    formatter: function(params) {
                                        if (params.value > 0) {
                                            return params.value;
                                        } else {
                                            return '';
                                        }
                                    }
                                }
                            }]
                        };

                        myChart.setOption(option);
                    }),
                    //本年供应商对账额
                    GetCodeData("VB21102611515334", "Get", "Goods").then(function(res) {
                        that.defaultDt1 = res.rows
                    }),
                    //年度采购订单类型
                    GetCodeData("VB21102611512642", "Get", "Goods").then(function(res) {
                        that.option2.series[0].data = res.rows
                        that.YearPurOrder.setOption(that.option2);
                    }),
                    //材料采购VS贸易采购
                    GetCodeData("VB21102617213167", "Get", "Goods").then(function(res) {
                        var 材料采购 = []
                        var 贸易采购 = []
                        res.rows.forEach(element => {

                            Object.values(element).forEach(item => {
                                if (element.type == "材料采购") {
                                    if (typeof(item) == "number") {
                                        材料采购.push(item)
                                    }
                                } else if (element.type == "贸易采购") {
                                    if (typeof(item) == "number") {
                                        贸易采购.push(item)
                                    }
                                }
                            });
                        });
                        that.option3.series[0].data = 材料采购
                        that.option3.series[1].data = 贸易采购
                        that.Purchase.setOption(that.option3);

                    }),
                    //常购材料
                    GetCodeData("VB21102714143844", "Get", "Goods").then(function(res) {
                        that.defaultDt2 = res.rows
                    }),
                    //主要材料价格异动分析
                    GetCodeData("VB21112716480028", "Get", "Goods").then(function(res) {
                        that.defaultDt3 = res.rows
                    })
            },
            //年度采购订单类型
            Kecutout(cellValue) {
                let _html = "";
                if (cellValue) {
                    _html += "<div>"
                    var _width1 = 100;
                    var _color = "";
                    _width1 = cellValue.row.total * 100 / cellValue.row.a;
                    if (_width1 > 100) {
                        _width1 = 100;
                    }
                    if (cellValue.row.total < cellValue.row.a) {
                        _color = "#00a000";
                    } else if (cellValue.row.total > cellValue.row.a) {
                        _color = "#FF0000";
                    } else {
                        _color = "#008000";
                    }

                    _html += ("<div  style='position: relative; width:120px;padding: 0px;background:#4199fe;overflow: hidden;height:27px;border: 1px solid #95b8e7;'><div style='width: " + _width1 + "%; display: block; position: relative; background: " + _color + "; color: #000; height: 40px; line-height: 40px;'>" +
                        "</div>" +
                        "<div style='position:absolute;width:100%;height:100%;top:0;display:flex;align-items:center;justify-content:center;color:black;'>" + cellValue.row.percentage + "%" + "</div>" +
                        "</div>" +
                        "");
                    return _html;
                }
            },
        },

        mounted() {
            TableAotoRoll([this.$refs.defaultDt1, this.$refs.defaultDt2,this.$refs.defaultDt3])
            var that = this
            setTimeout(function() {
                that.YearPurOrder = echarts.init(document.getElementById('YearPurOrder')),
                    that.GetTabelDate(that);
                that.Purchase = echarts.init(document.getElementById('Purchase')),
                    that.GetTabelDate(that);
            }, 0);
            setInterval(function() {
                that.GetTabelDate(that)
            }, 1000 * 60);
        }
    })
</script>



</html>